package com.zcxy.fast.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zcc
 * @create 2019/10/17 16:36
 * @Ver 1.0.0
 */
@Getter
@Setter
@ApiModel(value = "TreeNode", description = "树对象")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TreeNode implements Serializable {
    @ApiModelProperty(value = "主键")
    private String key;

    @ApiModelProperty(value = "名称")
    private String label;

    @ApiModelProperty(value = "图标")
    private String icon;

    @ApiModelProperty(value = "唯一编码")
    private String code;

    @ApiModelProperty(value = "子对象列表")
    private List<TreeNode> children;

    @ApiModelProperty(value = "是否有子对象")
    private boolean hasChildren;

    @ApiModelProperty(value = "父id")
    private String parentId;
    @JsonIgnore
    private Map<String, Object> attributes = new HashMap<String, Object>();

    public TreeNode() {

    }


    public Map<String, Object> getAttributes() {
        attributes.put("key", key);
        attributes.put("parentId", parentId);
        attributes.put("hasChildren", hasChildren);
        attributes.put("label", label);
        attributes.put("icon", icon);
        if (hasChildren) {
            attributes.put("children", null);
        }
        return attributes;
    }


}